<template>
  <div id="topicCheckTopSearch">
    <h1 class="con-right-title"> 话题评论审核 </h1>

    <div class="search-box">
      <el-form ref="ruleForm" :inline="true" :model="formInline" class="demo-form-inline">

        <el-form-item label="人审结果">
          <el-select v-model="formInline.manualAuditStatus" clearable>
            <el-option label="全部" value=""></el-option>
            <el-option label="通过" value="PASS"></el-option>
            <el-option label="未通过" value="UNPASS"></el-option>
            <el-option label="未审核" value="UNCHECKED"></el-option>
          </el-select>
        </el-form-item>
        
        <el-form-item label="机审结果">
          <el-select v-model="formInline.machineAuditStatus" clearable>
            <el-option label="全部" value=""></el-option>
            <el-option label="通过" value="PASS"></el-option>
            <el-option label="未通过" value="UNPASS"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="排序规则">
          <el-select v-model="formInline.sortType" clearable>
            <el-option
              v-for="item in orderList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-select v-model="formInline.timeType" clearable>
            <el-option
              v-for="(item, index) in timeTypeList"
              :key="'item' + index"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item label="内容搜索">
          <el-input v-model="formInline.searchText" placeholder="输入文字内容搜索" clearable></el-input>
        </el-form-item>

        <el-form-item label="圈子内帖子类型" label-width="110px !important">
          <el-select v-model="formInline.contentType" clearable>
            <el-option label="全部" value=""></el-option>
            <el-option label="图文" value="TEXT"></el-option>
            <el-option label="短视频" value="VIDEO"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="大鹏号">
          <el-input v-model="formInline.dpAccount" placeholder="输入大鹏号" clearable></el-input>
        </el-form-item>

        <el-form-item label="审核人">
          <el-select v-model="formInline.checkUserId" filterable clearable>
            <el-option
              v-for="(item, index) in personList"
              :key="'item' + index"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="用户属性">
          <el-select v-model="formInline.userProperty" clearable>
            <el-option label="全部" value=""></el-option>
            <el-option label="用户" value="REALUSER"></el-option>
            <el-option label="马甲" value="VEST"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch">
            查询
          </el-button>

          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { getDpNum } from '@/api/system/user'
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getCreateTime } from '@utils/pubFunction'

export default {
  name: 'topicCheckTopSearch',
  msg: '话题评论审核-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          manualAuditStatus: '', // 人审结果
          machineAuditStatus: '', // 机审结果
          sortType: '', // 排序规则
          searchText: '', // 内容查询
          contentType: '', // 帖子类型
          dpAccount: '', // 大鹏号
          timeType: '', // 时间类型
          checkUserId: '', // 审核人
          userProperty: '', // 用户属性
          startTime: '', // 开始时间
          endTime: '', // 结束时间
          createTime: []
        }
      }
    }
  },
  data() {
    return {
      // 排序
      orderList: [],
      // 时间类型
      timeTypeList: [],
      // 审核人
      personList: [{
        dapengUserId: '',
        nickname: '全部',
        userId:''
      }]
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getStatusList()
    this.getCheckUser()
  },
  methods: {
    /* 搜索 */
    toSearch() {
      this.$emit('toSearch')
    },

    /* 重置 */
    reset() {
      this.getCreateTime()
      //设置默认数据
      this.setDefaultValue()
    },

    // 设置默认时间
    getCreateTime() {
      const createTime = getCreateTime()
      this.formInline.createTime = createTime
    },

    /* 获取数据状态 */
    async getStatusList() {
      // 排序
      this.orderList = await sysNormalDisable('circle_topic_comment_sort')
      
      // 时间类型
      this.timeTypeList = await sysNormalDisable('circle_topic_query_time_type')
      
      this.setDefaultValue()

      //触发列表获取权限
      this.$emit('toSearch')
    },

    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.manualAuditStatus = ''
      this.formInline.machineAuditStatus = ''
      this.formInline.sortType = 'source.createdTime,asc'
      this.formInline.searchText = ''
      this.formInline.contentType = ''
      this.formInline.dpAccount = ''
      this.formInline.timeType = 'CREATE_DATE'
      this.formInline.checkUserId = ''
      this.formInline.userProperty = ''
      // this.formInline.createTime = []
    },

    // 审核人
    getCheckUser() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.personList = this.personList.concat(response)
      })
    }
  }
}
</script>

<style lang="less">
#topicCheckTopSearch {
  .el-input {
    &.el-input--suffix {
      width: 185px !important;
    }
  }

  label.el-form-item__label {
    width: 70px !important;
  }
}
</style>
